package com.exam.teacher.controller;

import com.exam.anno.MyLog;
import com.exam.entity.*;
import com.exam.entity.dto.ScoreDto;
import com.exam.entity.dto.StudentDto;
import com.exam.entity.dto.TeacherDto;
import com.exam.teacher.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    /**
     * 根据id来删除试卷
     * @param examCode
     * @return
     */
    @MyLog
    @DeleteMapping("/exam")
    public ApiResult deleteExamById(@RequestParam("examCode") Long examCode){
        return teacherService.deleteExamById(examCode);
    }

    /**
     * 修改试卷信息
     * @param examManage
     * @return
     */
    @MyLog
    @PutMapping("/exam")
    public ApiResult updateExam(@RequestBody ExamManage examManage){
        return teacherService.updateExam(examManage);
    }

    /**
     * 查询所有的试卷id信息
     * @return
     */
    @GetMapping("/examManagePaperId")
    public ApiResult getByPaperId(){
        return teacherService.getByPaperId();
    }

    /**
     * 添加考试信息
     * @param examManage
     * @return
     */
    @MyLog
    @PostMapping("/exam")
    public ApiResult insertExamInfo(@RequestBody ExamManage examManage){
        return teacherService.insertExamInfo(examManage);
    }

    /**
     * 查询所有的题目
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/answers/{page}/{size}")
    public ApiResult findAllAnswers(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return teacherService.findAllAnswers(page, size);
    }

    /**
     * 添加选择题并且添加试题管理
     * @param multiQuestion
     * @return
     */
    @MyLog
    @PostMapping("/MultiQuestion")
    public ApiResult addMultiQuestion(@RequestBody MultiQuestion multiQuestion){
        return teacherService.addMultiQuestion(multiQuestion);
    }

    /**
     * 添加填空题并且添加试题管理
     * @param fillQuestion
     * @return
     */
    @MyLog
    @PostMapping("/fillQuestion")
    public ApiResult addFillQuestion(@RequestBody FillQuestion fillQuestion){
//        System.out.println(fillQuestion);
        return teacherService.addFillQuestion(fillQuestion);
    }

    /**
     * 添加判断题并且添加试题管理
     * @param judgeQuestion
     * @return
     */
    @MyLog
    @PostMapping("/judgeQuestion")
    public ApiResult addJudgeQuestion(@RequestBody JudgeQuestion judgeQuestion){
        return teacherService.addJudgeQuestion(judgeQuestion);
    }

    /**
     * 查询所有的学生信息
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/students/{page}/{size}")
    public ApiResult findAllStudent(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        return teacherService.findAllStudent(page, size);
    }

    /**
     * 根据学生id查询该学生所有的分数
     * @param studentId
     * @return
     */
    @GetMapping("/score")
    public ApiResult findByStudentIdScore(@RequestParam("studentId") Long studentId){
        ScoreDto scoreDto = new ScoreDto();
        scoreDto.setStudentId(studentId);
        return teacherService.findByStudentIdScore(scoreDto);
    }

    /**
     * 根据试卷id查询实现成绩分段查询
     * @param examCode
     * @return
     */
    @GetMapping("/scores/{examCode}")
    public ApiResult findByExamCodeScore(@PathVariable("examCode") Long examCode){
        ScoreDto scoreDto = new ScoreDto();
        scoreDto.setExamCode(examCode);
        return teacherService.findByStudentIdScore(scoreDto);
    }

    /**
     * 学生管理编辑回显学生数据
     * @param studentId
     * @return
     */
    @GetMapping("/student/{studentId}")
    public ApiResult findByIdStudent(@PathVariable("studentId") Long studentId){
        StudentDto studentDto = new StudentDto();
        studentDto.setStudentId(studentId);
        return teacherService.findByIdStudent(studentDto);
    }

    /**
     * 学生管理编辑插入学生数据
     * @param studentDto
     * @return
     */
    @MyLog
    @PutMapping("/student")
    public ApiResult updateStudent(@RequestBody StudentDto studentDto){
        return teacherService.updateStudent(studentDto);
    }

    /**
     * 根据id删除学生信息
     * @param studentId
     * @return
     */
    @MyLog
    @DeleteMapping("/student/{studentId}")
    public ApiResult deleteByIdStudent(@PathVariable("studentId") Long studentId){
        return teacherService.deleteByIdStudent(studentId);
    }

    /**
     * 添加学生
     * @param studentDto
     * @return
     */
    @MyLog
    @PostMapping("/student")
    public ApiResult insertStudent(@RequestBody StudentDto studentDto){
        return teacherService.insertStudent(studentDto);
    }

    /**
     * 查找所有的教师分页
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/teachers/{page}/{size}")
    public ApiResult findAllTeacher(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        return teacherService.findAllTeacher(page, size);
    }

    /**
     * 教师管理编辑回显学生数据
     * @param teacherId
     * @return
     */
    @GetMapping("/teacher/{teacherId}")
    public ApiResult findByIdTeacher(@PathVariable("teacherId") Long teacherId){
        TeacherDto teacherDto = new TeacherDto();
        teacherDto.setTeacherId(teacherId);
        return teacherService.findByIdTeacher(teacherDto);
    }

    /**
     * 教师管理编辑插入教师数据
     * @param teacherDto
     * @return
     */
    @MyLog
    @PutMapping("/teacher")
    public ApiResult updateTeacher(@RequestBody TeacherDto teacherDto){
        return teacherService.updateTeacher(teacherDto);
    }

    /**
     * 根据id删除教师信息
     * @param teacherId
     * @return
     */
    @MyLog
    @DeleteMapping("/teacher/{teacherId}")
    public ApiResult deleteByIdTeacher(@PathVariable("teacherId") Long teacherId){
        return teacherService.deleteByIdTeacher(teacherId);
    }

    /**
     * 添加教师
     * @param teacherDto
     * @return
     */
    @MyLog
    @PostMapping("/teacher")
    public ApiResult insertTeacher(@RequestBody TeacherDto teacherDto){
        return teacherService.insertTeacher(teacherDto);
    }

}
